<?php
/* MyMeeting is an online meeting management software.
 * Copyright (C) 2009 Government Of Malaysia
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author: Abdullah Zainul Abidin, Nuhaa All Bakry
 *          Eavay Javay Barnad, Sarogini Muniyandi
 *
 */

class CommentComponent extends Object
{
/**
 * Define $controller
 *
 */
    var $controller;
/**
 * Define $args
 *
 */
    var $args=array('action'=>null);

/**
 * Describe startup
 *
 * @param $controller
 * @return null
 */
    function startup(&$controller){
        $args=$controller->passedArgs;
        $this->controller=$controller;
        if($args[0]=="comments"){
            $this->args['foreign_key']=$controller->action;
            if($args[1]=="view"){
                echo $this->list_comment();
                exit();
            }
            elseif($args[1]=="add"){
            }
        }
    }

/**
 * Describe list_comment
 *
 * @return null
 */
    function list_comment(){
        $controller=$this->controller;
        $cmtdata=$controller->{$controller->modelClass}->find('all',array(
            'conditions'=>array(
                $controller->modelClass.'.id' => $this->args['foreign_key']
            )
        ));
        if(count($cmtdata[0][$controller->modelClass.'Comment'])){
            $output="<ul>";
            foreach($cmtdata[0][$controller->modelClass.'Comment'] as $comment){
                $output.="<li>";
                $output.="<pre>".$comment['Comment']['description']."</pre>";
                $output.="<div class='commentdetails'>";
                $output.=$comment['Comment']['user_id'].' '.__('on',true).' '.date("d/m/Y (h:i a)",strtotime($comment['Comment']['updated']));
                $output.="</div>";
                $output.="</li>";
            }
            $output.="</ul>";
        }
        return $output;
    }
}
?>
